package org.changneng.framework.frameworkbusiness.controller;

import org.changneng.framework.frameworkbusiness.entity.Dept;
import org.changneng.framework.frameworkbusiness.entity.Position;
import org.changneng.framework.frameworkbusiness.entity.Users;
import org.changneng.framework.frameworkbusiness.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class PositionController {

    @Autowired
    private PositionService positionService;

    @RequestMapping("/insertPosition")
    public String inset(Position position,Model model){
        int i = positionService.insert(position);
        if (i>0){
            List<Position> list = positionService.selectAll();
            model.addAttribute("list",list);
            return "positionList";
        }
        return "positionList";
    }

    @RequestMapping("/selectPosition")
    public String selectPosition(Model model){
        List<Position> list = positionService.selectAll();
        model.addAttribute("list",list);
        return "positionList";
    }

    @RequestMapping("/deletePosition")
    public String deletePosition(int posid,Model model){
        int i = positionService.delete(posid);
        List<Position> list = positionService.selectAll();
        model.addAttribute("list",list);
        return "positionList";
    }

    @RequestMapping("/updatePosition")
    public String updatePosition(Position position, Model model){

        int i = positionService.update(position);
        List<Position> list = positionService.selectAll();
        model.addAttribute("list",list);
        return "positionList";
    }
}
